/**
 * Copyright 2015-2016 eyaomall.cn
 * All rights reserved.
 *
 * @project
 * @author jackey
 * @version 1.0
 * @date 2016-01-06
 */
package com.eyaomall.wxmall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eyaomall.wxmall.common.error.BECode;
import com.eyaomall.wxmall.common.helper.MemberHelper;
import com.eyaomall.wxmall.model.po.Collect;
import com.eyaomall.wxmall.service.CollectService;
import com.lycheeframework.core.cmp.api.http.GsnData;
import com.lycheeframework.core.cmp.api.http.GsnResponse;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;
import com.lycheeframework.core.common.util.StringUtil;
import com.lycheeframework.core.exception.ErrorCodeException;
/**
 * 收藏
 * @author yuhuafeng
 * @date 2016-9-7
 */
@Controller
@RequestMapping("collect")
public class CollectController {
	@Autowired
	private CollectService collectService;
	
	
	/**
	 * 跳转至我的收藏列表
	 * @return
	 */
	@RequestMapping("page")
	public  String page(){
		return "collect/page";
	}
	
	
	/**
	 * 新增我的收藏
	 * @param collect
	 * @return
	 */
	@RequestMapping("create")
	public @ResponseBody GsnData createCollect(Collect collect){
		collect.setMemberId(MemberHelper.getId());//MmeberHelper.getMemberId();
		return  GsnResponse.toData(collectService.create(collect));
	}
	
	/**
	 * 查看我的收藏列表
	 * @param collect
	 * @param httpObject
	 * @return
	 */
	@RequestMapping("page_data")
	public @ResponseBody GsnData pageData(Collect collect,PageHTTPObject httpObject){
		collect.setMemberId(MemberHelper.getId());
		return GsnResponse.toData(collectService.page(collect, httpObject));
	}	
	/**
	 * 删除我的收藏
	 * @param memberId
	 * @return
	 */
	@RequestMapping("deleteByMemberId")
	public @ResponseBody GsnData deleteByMemberId(Integer id){
		return GsnResponse.toData(collectService.deleteByMemberId(id));
	}
	
	
	/**
	 * 批量删除
	 * @return
	 */
	@RequestMapping("bitchdelete")
	public @ResponseBody GsnData bitchdelete(String ids){
		if(StringUtil.isEmpty(ids))
			throw new ErrorCodeException(BECode.global_900001); 
		return GsnResponse.toData(collectService.bitchdelete(ids));
	}
	
}
